# Powermeter 测试构建文件

if meson_build
  drivers_install_dir = meson.project_build_root() / 'opt/bmc/drivers'
else
  drivers_install_dir = 'opt/bmc/drivers/'
endif
run_command('mkdir', '-p', drivers_install_dir, check: false)

# INA I2cStub库源文件
ina_i2c_stub_sources = [
  '../../bus/i2c/drivers/i2c.cpp',
]

# 创建INA I2cStub动态库
powermeter_i2c_stub_lib = shared_library(
  'I2cStubPowermeter',
  ina_i2c_stub_sources,
  include_directories: [
    include_directories('../../../../drivers/bus/i2c'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../tests/drivers/bus/i2c'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
  ],
  dependencies: [libmcpp_deps, internal_dep, test_utils_dep],
  install: false,
)

# 创建INA I2cStub依赖
powermeter_i2c_stub_dep = declare_dependency(
  link_with: powermeter_i2c_stub_lib,
  include_directories: [
    include_directories('../../../../drivers/bus/i2c'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../tests/drivers/bus/i2c'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
  ],
  dependencies: [libmcpp_deps],
)

powermeter_test_sources = [
  '../../../main.cpp',
  'test_powermeter_abi.cpp',
  '../../../../drivers/chip/powermeter/interface/i_ina.cpp',
  '../../../../drivers/chip/powermeter/ina.cpp',
] + chip_interface_sources

powermeter_test = executable(
  'test_powermeter_abi',
  powermeter_test_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../../..'),
    include_directories('../../../../drivers/bus/i2c'),
    include_directories('../../../../drivers/chip/powermeter'),
    include_directories('../../../../drivers/chip'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../drivers/internal/chip/chip_ina'),
    include_directories('../../../../drivers/internal/bus/bus_base'),
    include_directories('../../../../tests/drivers/bus/i2c'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    test_utils_dep,
    powermeter_i2c_stub_dep,
    internal_dep,
    ina_dep,
    i2c_dep,
  ],
  cpp_args: ['-UHAVE_LIBSOC_ADAPTER'],
  install: false,
)

test('test_powermeter_abi', powermeter_test, timeout: 300, suite: 'powermeter')

# INA 单元测试
powermeter_unit_test_sources = [
  '../../../main.cpp',
  'test_powermeter.cpp',
]

powermeter_unit_test = executable(
  'test_powermeter',
  powermeter_unit_test_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../../..'),
    include_directories('../../../../drivers/internal/chip/chip_ina'),
    include_directories('../../../../drivers/internal/chip/chip_base'),
    include_directories('../../../../drivers/internal/bus/bus_base'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    test_utils_dep,
    libmcpp_deps,
    internal_dep,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
  link_whole: [internal_static_lib],
)

test('test_powermeter', powermeter_unit_test, timeout: 300, suite: 'powermeter')
